package org.singledog.form.builder.parser.freemarker.parser;

import org.singledog.form.builder.parser.AbstractComponentParser;
import org.singledog.form.builder.parser.freemarker.FreeMarkerContants;
import org.singledog.form.builder.parser.freemarker.freemarker.FreeMarkerConfiguration;
import org.singledog.form.builder.storage.FileSchemaReader;

public abstract class AbstractFreemarkerParser extends AbstractComponentParser {

    protected String schemaDirectory() {
        return supportType().name().toLowerCase();
    }

    protected String getSchema(String code) {
        String path = FreeMarkerContants
                .getBaseSchemaDirectory()
                .concat(schemaDirectory())
                .concat("/")
                .concat(code)
                .concat(".json");

        if (!FreeMarkerConfiguration.isUseCache()) {
            FileSchemaReader.clearCache();
        }

        return FileSchemaReader.getSchema(path);
    }

}
